package com.ruoyi.web.controller.repair;

import cn.hutool.core.io.file.FileWriter;
import com.ruoyi.Electronic.domain.HouseRepairElectronicT;
import com.ruoyi.Electronic.service.IHouseRepairElectronicService;
import com.ruoyi.area.domain.HouseAreaT;
import com.ruoyi.area.service.IHouseAreaTService;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.poi.DocUtils;
import com.ruoyi.data.DataUtils;
import com.ruoyi.data.NumberData;
import com.ruoyi.data.domain.ParameterSingleT;
import com.ruoyi.data.service.IParameterSingleService;
import com.ruoyi.date.DateFormater;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.door.service.IHouseDoorTService;
import com.ruoyi.project.domain.HouseProjectT;
import com.ruoyi.project.domain.ParameterSingleVO;
import com.ruoyi.project.service.IHouseProjectTService;
import com.ruoyi.repairArea.domain.HouseRepairAreaT;
import com.ruoyi.util.ExcelUtils;
import com.ruoyi.util.FileUtil;
import com.ruoyi.util.SysParamKey;
import com.sun.media.jfxmedia.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.*;


@RestController
@RequestMapping("/repair/annex")
public class HouseRepairElectronicController extends BaseController {
    @Autowired
    private IHouseProjectTService houseProjectTService;
    @Autowired
    private IParameterSingleService parameterSingleService;
    @Autowired
    private IHouseAreaTService houseAreaTService;
    @Autowired
    private IHouseDoorTService houseDoorTService;
    @Autowired
    private IHouseRepairElectronicService houseRepairElectronicService;
    private List<HouseProjectT> houseProjectList = new ArrayList<HouseProjectT>();
    private List<HouseRepairElectronicT> groupList = new ArrayList<HouseRepairElectronicT>();
    private List<HouseRepairElectronicT> unitList = new ArrayList<HouseRepairElectronicT>();
    private List<HouseRepairElectronicT> doorList = new ArrayList<HouseRepairElectronicT>();

    private String targetFileName;
    private String generateFileName;
//    private String urlWord="111.26.101.245:8433/PRINT/";
//    private String urlWord="localhost:80/PRINT/";
    private String urlWord="zanysoft.xyz:8433/PRINT/";
/*    private String urlWord="17.17.17.17/PRINT/";*/
    private HttpServletResponse response;


    /**
     * 查询维修项目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseRepairElectronicT houseRepairElectronicT) {
        ParameterSingleT vo = new ParameterSingleT();
        vo.setParamCode(SysParamKey.PHOTO_HTTP.getKey());
        vo = parameterSingleService.getSysParams(vo);
        startPage();
        List<HouseRepairElectronicT> list = houseRepairElectronicService.selectAnnexList(houseRepairElectronicT);
        for(HouseRepairElectronicT houseRepairElectronicVo : list){
            houseRepairElectronicVo.setElectronicImageUrl(vo.getParamVal()+houseRepairElectronicVo.getElectronicHttp());
        }
        return getDataTable(list);
    }

    private ParameterSingleVO parameterSingleVO = new ParameterSingleVO();
    @GetMapping("/downloadOne")
    public AjaxResult downloadOne(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        Map map = new HashMap();
        HouseProjectT projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex1.doc";
        generateFileName = "工程预算书" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    @GetMapping("/downloadTwo")
    public AjaxResult downloadTwo(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex2.doc";
        generateFileName = "维修前照片" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }
    @GetMapping("/downloadThree")
    public AjaxResult downloadThree(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        map.put("companyName", projectVO.getCompanyName());
        map.put("companyer", projectVO.getCompanyer());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("userNumber", userNumber.toString());
        map.put("infoName", projectVO.getInfoName());
        map.put("seat", areaVO.getSeat());
        map.put("areaName", projectVO.getAreaName());
        map.put("projectName", projectVO.getProjectName());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex3.xlsx";
        generateFileName = "费用划拨单" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }
    //附件4
    @GetMapping("/downloadFour")
    public AjaxResult downloadFour(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseDoorT houseDoorVO = new HouseDoorT();
        HouseAreaT houseAreaVO = new HouseAreaT();
        houseAreaVO.setAreaName(projectVO.getAreaName());
        houseAreaVO = houseAreaTService.getCostNum(houseAreaVO);
        houseDoorVO.setAreaName(projectVO.getAreaName());
        houseDoorVO = houseDoorTService.getDoorNumber(houseDoorVO);
        Double costRatio = 0d;
        costRatio = DataUtils.doubleScale1(Double.valueOf(houseAreaVO.getCostNum()) / Double.valueOf(houseDoorVO.getDoorNumber())) * 100;
        HouseProjectT projectTemp = new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        Integer userNumber1 = DataUtils.method(Integer.valueOf(houseDoorVO.getDoorNumber()),userNumber);
        map.put("projectaddr", projectVO.getProjectaddr());
        map.put("costRatio", costRatio.toString());
        map.put("userNumber1", userNumber1.toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex4.doc";
        generateFileName = "不受理告知书" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    @GetMapping("/downloadFive")
    public AjaxResult downloadFive(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        HouseRepairElectronicT groupVO=new HouseRepairElectronicT();
        groupVO.setAreaName(projectVO.getAreaName());
        groupVO=houseRepairElectronicService.getGroupSum(groupVO);
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        HouseRepairElectronicT doorVO=new HouseRepairElectronicT();
        doorVO.setAreaName(projectVO.getAreaName());
        doorVO=houseRepairElectronicService.getHouseDoorTsum(doorVO);
        String groupAll="";
        String unitNumber="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
            unitNumber=unitList.get(i).getUnitNumber();
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Double balance = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            balance += houseProjectList.get(i).getBalance();
            userNumber = userNumber + 1;
        }
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("areaName", projectVO.getAreaName());
        map.put("seat", areaVO.getSeat());
        map.put("estateName", areaVO.getEstateName());

        map.put("groupSum", groupVO.getGroupSum());
        map.put("companyName", projectVO.getCompanyName());
        map.put("infoName", projectVO.getInfoName());
        map.put("unitName", projectVO.getUnitName());
        map.put("projectName", projectVO.getProjectName());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("payMoney", projectVO.getPayMoney().toString());
        map.put("userNumber", userNumber.toString());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("price", DataUtils.doubleScale2(price).toString());
        map.put("balance",  DataUtils.doubleScale2(balance).toString());
        map.put("groupAll", groupAll);
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex5.xlsx";
        generateFileName = "备案表" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }
    @GetMapping("/downloadSix")
    public AjaxResult downloadSix(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT vo=new HouseRepairElectronicT();
        HouseRepairElectronicT maxVO=new HouseRepairElectronicT();
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        HouseRepairElectronicT doorVO=new HouseRepairElectronicT();
        doorVO.setAreaName(projectVO.getAreaName());
        doorVO=houseRepairElectronicService.getHouseDoorTsum(doorVO);
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        vo.setAreaName(projectVO.getAreaName());
        vo.setGroupName(projectVO.getGroupName());
        vo.setUnitName(projectVO.getUnitName());
        maxVO= houseRepairElectronicService.getMaxDate(vo);
        HouseProjectT projectTemp = new HouseProjectT();
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        map.put("areaName", projectVO.getAreaName());
        map.put("seat", areaVO.getSeat());
        map.put("areaBuild", areaVO.getAreaBuild());
        map.put("areaEnd", DateFormater.formatDate(areaVO.getAreaEnd()));
        map.put("projectName", projectVO.getProjectName());
        map.put("doorSpaceSum",doorVO.getDoorSpaceSum());
        map.put("doorSum",doorVO.getDoorSum());
        map.put("infoName", projectVO.getInfoName());
        map.put("maxDate", maxVO.getCreateDate());
        map.put("groupName", projectVO.getGroupName());
        map.put("unitName", projectVO.getUnitName());
        map.put("userNumber", userNumber.toString());
        map.put("space",  DataUtils.doubleScale2(space).toString());
        map.put("groupAll", groupAll);
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex6.doc";
        generateFileName = "维修照片后" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    @GetMapping("/downloadSeven")
    public AjaxResult downloadSeven(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        map.put("areaName", projectVO.getAreaName());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("projectaddr", projectVO.getProjectaddr());
        map.put("infoName", projectVO.getInfoName());
        map.put("committeeTel", projectVO.getCommitteeTel());
        map.put("communityTel", projectVO.getCommunityTel());
        map.put("homeTel", projectVO.getHomeTel());
        map.put("projectLimit", projectVO.getProjectLimit());
        map.put("userNumber",  userNumber.toString());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("groupAll", groupAll);
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        map.put("week", DateFormater.dateFormatWeek(DateFormater.getSystemCurrentDateYYYY()+
                DateFormater.getSystemCurrentDateMM()+DateFormater.getSystemCurrentDateDD()));
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex7.doc";
        generateFileName = "申请使用维修资金公示" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件8
    @GetMapping("/downloadEight")
    public AjaxResult downloadEight(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        map.put("areaName", projectVO.getAreaName());
        map.put("committeeTel", projectVO.getCommitteeTel());
        map.put("committeer", projectVO.getCommitteer());
        map.put("communityTel", projectVO.getCommunityTel());
        map.put("communityer", projectVO.getCommunityer());
        map.put("streeter", projectVO.getStreeter());
        map.put("streetTel", projectVO.getStreetTel());
        map.put("homeTel", projectVO.getHomeTel());
        map.put("homer", projectVO.getHomer());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex8.xlsx";
        generateFileName = "维修资金使用申请人资格认定证明" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }


    @GetMapping("/downloadNine")
    public AjaxResult downloadNine(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        HouseProjectT projectTemp = new HouseProjectT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("seat", areaVO.getSeat());
        map.put("price", DataUtils.doubleScale2(price).toString());
        map.put("space",  DataUtils.doubleScale2(space).toString());
        map.put("price",  price.toString());
        map.put("areaName", projectVO.getAreaName());
        map.put("groupAll", groupAll);
        map.put("projectaddr", projectVO.getProjectaddr());
        map.put("projectLimit", projectVO.getProjectLimit());
        map.put("companyName", projectVO.getCompanyName());
        map.put("infoName", projectVO.getInfoName());
        map.put("projectName", projectVO.getProjectName());
        map.put("trueMoney", projectVO.getTrueMoney().toString());
        map.put("projectStart", DateFormater.formatDate(projectVO.getProjectStart()).toString());
        map.put("projectEnd", DateFormater.formatDate(projectVO.getProjectEnd()).toString());
        int projectEnd1= Integer.parseInt(projectVO.getProjectLimit())*365;
        Date limitDate=DateFormater.addDaysToDate(projectVO.getProjectEnd(),projectEnd1);
        map.put("limitDate", DateFormater.formatDate(limitDate).toString());
        map.put("minusDate", DateFormater.dateSubtraction(projectVO.getProjectEnd(),projectVO.getProjectStart()).toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex9.doc";
        generateFileName = "施工合同" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件10
    @GetMapping("/downloadTen")
    public AjaxResult downloadTen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        map.put("areaName", projectVO.getAreaName());
        map.put("groupAll", groupAll);
        map.put("infoName", projectVO.getInfoName());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex10.doc";
        generateFileName = "维修资金使用查档申请" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }


    //附件4
    @GetMapping("/downloadEleven")
    public AjaxResult downloadEleven(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        map.put("projectName", projectVO.getProjectName());
        map.put("projectStart", DateFormater.formatDate(projectVO.getProjectStart()).toString());
        map.put("projectEnd", DateFormater.formatDate(projectVO.getProjectEnd()).toString());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("projectMoney1", NumberData.makeUpperCaseSum(projectVO.getProjectMoney().toString()));
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex11.doc";
        generateFileName = "竣工验收报告" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件12
    @GetMapping("/downloadTwelve")
    public AjaxResult downloadTwelve(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT doorVO=new HouseRepairElectronicT();
        HouseProjectT projectTemp = new HouseProjectT();
        doorVO.setAreaName(projectVO.getAreaName());
        doorVO=houseRepairElectronicService.getHouseDoorTsum(doorVO);
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        HouseRepairElectronicT groupVO=new HouseRepairElectronicT();
        groupVO.setAreaName(projectVO.getAreaName());
        groupVO=houseRepairElectronicService.getGroupSum(groupVO);
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("groupSum", groupVO.getGroupSum());
        map.put("price", price.toString());
        map.put("areaName", projectVO.getAreaName());
        map.put("estateName", areaVO.getEstateName());
        map.put("seat", areaVO.getSeat());
        map.put("groupAll", groupAll);
        map.put("projectName", projectVO.getProjectName());
        map.put("doorSpaceSum",doorVO.getDoorSpaceSum());
        map.put("doorSum",doorVO.getDoorSum());
        map.put("groupName", projectVO.getGroupName());
        map.put("userNumber", userNumber.toString());
        map.put("costMoney",doorVO.getCostMoney().toString());
        map.put("infoName", projectVO.getInfoName());
        map.put("projectStart", DateFormater.formatDate(projectVO.getProjectStart()).toString());
        map.put("projectEnd", DateFormater.formatDate(projectVO.getProjectEnd()).toString());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("areaEnd", DateFormater.formatDate(areaVO.getAreaEnd()));
        map.put("companyName", projectVO.getCompanyName());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex12.doc";
        generateFileName = "房屋共用部位共用设施设备" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件13
    @GetMapping("/downloadThirteen")
    public AjaxResult downloadThirteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        HouseProjectT projectTemp=new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Double balancesum = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            balancesum += houseProjectList.get(i).getBalance();
            userNumber = userNumber + 1;
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        HouseRepairElectronicT doorVO=new HouseRepairElectronicT();
        doorVO.setAreaName(projectVO.getAreaName());
        doorVO=houseRepairElectronicService.getHouseDoorTsum(doorVO);
        map.put("space",  DataUtils.doubleScale2(space).toString());
        map.put("userNumber",  userNumber.toString());
        map.put("doorSum",doorVO.getDoorSum());
        map.put("costMoney",doorVO.getCostMoney().toString());
        map.put("balancesum", DataUtils.doubleScale2(balancesum).toString());
        map.put("trueMoney", projectVO.getTrueMoney().toString());
        map.put("payMoney", projectVO.getPayMoney().toString());
        map.put("projectName", projectVO.getProjectName());
        map.put("communityName", areaVO.getCommunityName());
        map.put("projectEnd", projectVO.getProjectEnd());
        map.put("communityer", projectVO.getCommunityer());
        map.put("communitytel", projectVO.getCommunityer());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex13.xlsx";
        generateFileName = "划拨备案登记表" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件14
    @GetMapping("/downloadFourteen")
    public AjaxResult downloadFourteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        HouseProjectT projectTemp = new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        HouseRepairElectronicT doorVO=new HouseRepairElectronicT();
        doorVO.setAreaName(projectVO.getAreaName());
        doorVO=houseRepairElectronicService.getHouseDoorTsum(doorVO);
        map.put("projectName", projectVO.getProjectName());
        map.put("seat", areaVO.getSeat());
        map.put("groupAll", groupAll);
        map.put("areaEnd", DateFormater.formatDate(areaVO.getAreaEnd()));
        map.put("doorSpaceSum",doorVO.getDoorSpaceSum());
        map.put("userNumber", userNumber.toString());
        map.put("unitName", projectVO.getUnitName());
        map.put("areaBuild", areaVO.getAreaBuild());
        map.put("communityName", areaVO.getCommunityName());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex14.xlsx";
        generateFileName = "现场踏查报告" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }
    //附件15
    @GetMapping("/downloadFifteen")
    public AjaxResult downloadFifteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        HouseProjectT projectTemp = new HouseProjectT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("price", DataUtils.doubleScale2(price).toString());
        map.put("space",  DataUtils.doubleScale2(space).toString());
        map.put("price",  price.toString());
        map.put("areaName", projectVO.getAreaName());
        Double payMoney1=projectVO.getPayMoney()*0.7;
        Double payMoney2=projectVO.getPayMoney()*0.3;
        map.put("payMoney1", payMoney1.toString());
        map.put("payMoney2", payMoney2.toString());
        map.put("groupAll", groupAll);
        map.put("projectaddr", projectVO.getProjectaddr());
        map.put("projectLimit", projectVO.getProjectLimit());
        map.put("projectName", projectVO.getProjectName());
        map.put("trueMoney", projectVO.getTrueMoney().toString());
        map.put("projectStart", DateFormater.formatDate(projectVO.getProjectStart()).toString());
        map.put("projectEnd", DateFormater.formatDate(projectVO.getProjectEnd()).toString());
        int projectEnd1= Integer.parseInt(projectVO.getProjectLimit())*365;
        Date limitDate=DateFormater.addDaysToDate(projectVO.getProjectEnd(),projectEnd1);
        map.put("limitDate", DateFormater.formatDate(limitDate).toString());
        map.put("minusDate", DateFormater.dateSubtraction(projectVO.getProjectEnd(),projectVO.getProjectStart()).toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex15.doc";
        generateFileName = "维修资金使用流程及准备资料" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件16
    @GetMapping("/downloadSixteen")
    public AjaxResult downloadSixteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double balancesum = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            balancesum += houseProjectList.get(i).getBalance();
            userNumber = userNumber + 1;
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        map.put("areaName", projectVO.getAreaName());
        map.put("balancesum", DataUtils.doubleScale2(balancesum).toString());
        map.put("seat", areaVO.getSeat());
        map.put("communityName", areaVO.getCommunityName());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex16.xlsx";
        generateFileName = "维修资金使用业务受理单" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,null);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }
    //附件4
    @GetMapping("/downloadSeventeen")
    public AjaxResult downloadSeventeen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        map.put("areaName", projectVO.getAreaName());
        map.put("infoName", projectVO.getInfoName());
        map.put("estateName", areaVO.getEstateName());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex17.doc";
        generateFileName = "维修资金使用申请" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件18
    @GetMapping("/downloadEighteen")
    public AjaxResult downloadEighteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        map.put("areaName", projectVO.getAreaName());
        map.put("streetName", areaVO.getSeat());
        map.put("communityName", areaVO.getCommunityName());
        map.put("projectName", projectVO.getProjectName());
        map.put("companyName", projectVO.getCompanyName());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex18.doc";
        generateFileName = "委托书" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件19
    @GetMapping("/downloadNineteen")
    public AjaxResult downloadNineteen(HouseProjectT houseProjectT) throws Exception {
        if(houseProjectT.getProjectId()==null){
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId=houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if(projectVO==null){
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        HouseRepairElectronicT unitVO=new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitVO.setProjectId(projectVO.getProjectId());
        unitList=houseRepairElectronicService.getUnitListAll(unitVO);
        String groupAll="";
        for (int i = 0; i < unitList.size(); i++) {
            groupAll += unitList.get(i).getProjectaddr()+",";
        }
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        HouseRepairElectronicT doorVO2=new HouseRepairElectronicT();
        doorVO2.setAreaName(projectVO.getAreaName());
        doorVO2=houseRepairElectronicService.getHouseDoorTsum(doorVO2);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        doorList=houseRepairElectronicService.getDoorByRepairList(unitVO);
        List datelist = new ArrayList();
        for (HouseRepairElectronicT doorVO : doorList) {
            Map dateMap = new HashMap();
            dateMap.put("purposeName", doorVO.getPurposeName());
            dateMap.put("groupName", doorVO.getGroupName());
            dateMap.put("unitName", doorVO.getUnitName());
            dateMap.put("doorName", doorVO.getDoorName());
            dateMap.put("userName", doorVO.getUserName());
            dateMap.put("papersCode", doorVO.getPapersCode());
            dateMap.put("tel", doorVO.getTel());
            dateMap.put("houseId", doorVO.getHouseId().toString());
            dateMap.put("repairMoney", doorVO.getRepairMoney().toString());
            dateMap.put("payMoney", doorVO.getPayMoney().toString());
            dateMap.put("costMoney", doorVO.getCostMoney().toString());
            dateMap.put("balance", doorVO.getBalance().toString());
            dateMap.put("noMoney", doorVO.getNoMoney().toString());
            dateMap.put("space", doorVO.getSpace().toString());
            datelist.add(dateMap);
        }
        map.put("datelist", datelist);
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("price", DataUtils.doubleScale2(price).toString());
        map.put("areaName", projectVO.getAreaName());
        map.put("groupName", projectVO.getGroupName());
        map.put("doorSum",doorVO2.getDoorSum());
        map.put("projectName", projectVO.getProjectName());
        map.put("infoName", projectVO.getInfoName());
        map.put("payMoney", projectVO.getPayMoney());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex19.xlsx";
        generateFileName = "业主签名表" + DateFormater.getSystemCurrentDateFull() + ".xlsx";
        String filePath = path + generateFileName;
        File file = new File(path+targetFileName);
        try {
            byte[] bytes = ExcelUtils.writeExcel(file,map,datelist);
            File file0=new File(path+generateFileName);
            FileWriter writer = new FileWriter(file0);
            writer.write(bytes,0,bytes.length);
            //FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        //File file = new File(filePath);
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    //附件20
    @GetMapping("/downloadTwenty")
    public AjaxResult downloadTwenty(HouseProjectT houseProjectT) throws Exception {
        if (houseProjectT.getProjectId() == null) {
            return AjaxResult.error("请输入工程编号在进行下载附件");
        }
        String projectId = houseProjectT.getProjectId();
        HouseProjectT projectVO = new HouseProjectT();
        Map map = new HashMap();
        projectVO = houseProjectTService.selectHouseProjectTByProjectId(projectId);
        if (projectVO == null) {
            return AjaxResult.error("该工程编号有误,没有该工程编号");
        }
        HouseProjectT projectTemp = new HouseProjectT();
        HouseRepairElectronicT unitVO = new HouseRepairElectronicT();
        unitVO.setAreaName(projectVO.getAreaName());
        unitVO.setGroupName(projectVO.getGroupName());
        unitVO.setUnitName(projectVO.getUnitName());
        unitList = houseRepairElectronicService.getUnitListAll(unitVO);
        doorList=houseRepairElectronicService.getDoorList(unitVO);
        projectTemp.setProjectId(projectVO.getProjectId());
        houseProjectList = houseProjectTService.getRepairListAll(projectTemp);
        Double space = 0d;
        Integer userNumber = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            userNumber = userNumber + 1;
        }
        projectVO.setSignSts("1");
        HouseProjectT houseProjectT1 = new HouseProjectT();
        houseProjectT1 = houseProjectTService.selectRepairBySignSts(projectVO);
        HouseProjectT houseProjectT2 = new HouseProjectT();
        projectVO.setSignSts("");
        houseProjectT2 = houseProjectTService.selectRepairBySignSts(projectVO);
        if(houseProjectT2.getSignSum()==0){
            projectVO.setSignSum(0d);
        }else{
            projectVO.setSignSum(DataUtils.divideMoney(houseProjectT1.getSignSum(),houseProjectT2.getSignSum()));
        }
        Integer vote = 0;
        Integer vote1 = 0;
        for (int i = 0; i < houseProjectList.size(); i++) {
            space += houseProjectList.get(i).getSpace();
            if("1".equals(houseProjectList.get(i).getSignSts())){
                vote +=vote+1;
            }
        }
        map.put("vote1", vote1.toString());
        map.put("signSum", projectVO.getSignSum().toString());
        HouseRepairElectronicT areaVO=new HouseRepairElectronicT();
        areaVO.setAreaName(projectVO.getAreaName());
        areaVO=houseRepairElectronicService.areaInfoSelect(areaVO);
        Double price = 0d;
        price= DataUtils.divideMoney(projectVO.getProjectMoney(),space);
        map.put("areaName", projectVO.getAreaName());
        map.put("areaEnd", DateFormater.formatDate(areaVO.getAreaEnd()));
        map.put("infoName", projectVO.getInfoName());
        map.put("userNumber", userNumber.toString());
        map.put("space", DataUtils.doubleScale2(space).toString());
        map.put("projectMoney", projectVO.getProjectMoney().toString());
        map.put("publicityStart", DateFormater.formatDate(projectVO.getPublicityStart()).toString());
        map.put("publicityEnd", DateFormater.formatDate(projectVO.getPublicityEnd()).toString());
        map.put("vote", vote.toString());
        map.put("companyName", projectVO.getCompanyName());
        map.put("year", DateFormater.getSystemCurrentDateYYYY());
        map.put("month", DateFormater.getSystemCurrentDateMM());
        map.put("date", DateFormater.getSystemCurrentDateDD());
        parameterSingleVO.setParamCode(SysParamKey.PRINT.getKey());
        ParameterSingleVO ss = houseProjectTService.getSysParams(parameterSingleVO);
        String path = ss.getParamVal();
        targetFileName = "annex20.doc";
        generateFileName = "业主会议决议" + DateFormater.getSystemCurrentDateFull() + ".doc";
        String filePath = path + generateFileName;
        try {
            DocUtils.writeWord(map, path, targetFileName, generateFileName);
            FileUtil.downFile(path + generateFileName, generateFileName, response);
        } catch (Exception e) {
        }
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("addr",urlWord + generateFileName);
        return AjaxResult.success(map1);
    }

    @PostMapping("/photo")
    public AjaxResult uploadPhoto(@RequestBody HouseRepairElectronicT houseRepairElectronicT) {
        houseRepairElectronicT.setCreater(getUsername());
        return toAjax(houseRepairElectronicService.insertElectronicPhoto(houseRepairElectronicT));
    }

    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws Exception {
        try {
            HouseRepairElectronicT houseRepairElectronicT = new HouseRepairElectronicT();
            ParameterSingleT vo = new ParameterSingleT();
            vo.setParamCode(SysParamKey.E_RECORD.getKey());
            vo = parameterSingleService.getSysParams(vo);
            ParameterSingleT vo1 = new ParameterSingleT();
            vo1.setParamCode(SysParamKey.PHOTO_HTTP.getKey());
            vo1 = parameterSingleService.getSysParams(vo1);
            // 上传文件路径
//            String filePath = RuoYiConfig.getUploadPath();
            String filePath = vo.getParamVal();
            // 上传并返回新文件名称
            String fileName = FileUploadUtils.upload(filePath, file);
            AjaxResult ajax = AjaxResult.success();
            ajax.put("fileName", fileName);
            ajax.put("fileUrl", vo1.getParamVal()+fileName);
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

}
